package com.example.administrator.yuejian_2.adapter;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.yuejian_2.R;
import com.example.administrator.yuejian_2.bean.MasterCollectBean;
import com.example.administrator.yuejian_2.viewholder.MasterCollectListViewHolder;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/11/10.
 */

public class MasterCollectListAdapter extends RecyclerView.Adapter {


    private List<MasterCollectBean> master = new ArrayList<>();
    private Context context;
    private LayoutInflater layoutInflater;
    private int mid,uid;

    public MasterCollectListAdapter(Context context, List<MasterCollectBean> master){
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
        this.master.addAll(master);
        SharedPreferences sharedPreferences = context.getSharedPreferences("userInfo",
                Context.MODE_PRIVATE);
        uid = sharedPreferences.getInt("user_id",0);

    }




    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = layoutInflater.inflate(R.layout.item_mastercollect,parent,false);
        MasterCollectListViewHolder holder = new MasterCollectListViewHolder(itemView);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        MasterCollectListViewHolder masterholder = (MasterCollectListViewHolder) holder;
        MasterCollectBean masterlist = master.get(position);
        masterholder.mastername.setText(masterlist.getC_name());
        String picture = masterlist.getC_pic();
        if (!picture.equals(""))
            Picasso.with(context).
                    load("http://10.0.2.2/yuejian16/Public/clubphoto/"+picture)
                    .into(masterholder.masterpic);

        final int mid = masterlist.getMid();
//        masterholder.itemView.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                Intent intent = new Intent(context, MasterDetailActivity.class);
//                intent.putExtra("mid",mid);
//                context.startActivity(intent);
//
//            }
//        });


    }

    @Override
    public int getItemCount() {

        return master.size();
    }
}



